package com.atguigu.gmall.product.rpc;

import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.vo.CategoryTreeVo;
import com.atguigu.gmall.starter.cache.aspect.annotation.MallCache;
import net.bytebuddy.agent.builder.AgentBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: CategoryRpcController
 * @Author: WDD
 * @CreateTime: 2022-12-07  22:23
 * @Description: 内部调用接口
 */
@RestController
@RequestMapping("/api/inner/rpc/product/")
public class CategoryRpcController {

    @Autowired
    BaseCategory1Service baseCategory1Service;

    //分类树形结构数据
    @MallCache(cacheKey = RedisConst.CATEGORY_CACHE)
    @GetMapping("category/tree")
    public Result<List<CategoryTreeVo>> getCategoryTree(){
        List<CategoryTreeVo> list = baseCategory1Service.getCategoryTree();
        return Result.ok(list);
    }

    //
    @GetMapping("category/view/{cId}")
    public Result<CategoryTreeVo> getCategoryTreeByCId(@PathVariable("cId") Long cId){
        CategoryTreeVo categoryTreeVo = baseCategory1Service.getCategoryTreeByCId(cId);
        return Result.ok(categoryTreeVo);
    }
}
